#pragma once

#include "RequestAndRespond.hpp"

// 网络标准计算机
// 只需要处理将request -> respond

class NetCal
{
private:
public:
    NetCal() {}
    std::shared_ptr<Response> Caculator(std::shared_ptr<Request> req)
    {
        auto resp = Factory::BuildResponseDefault();

        switch (req->Oper())
        {
        case '+':
            resp->_result = req->X() + req->Y();
            break;
        case '-':
            resp->_result = req->X() - req->Y();
            break;
        case '*':
            resp->_result = req->X() * req->Y();
            break;
        case '/':
            if (req->Y() == 0)
            {
                resp->_code = 2;
                resp->_desc = "mode zero";
                break;
            }
            resp->_result = req->X() / req->Y();
            break;
        default:
            resp->_code = 3;
            resp->_desc = "illegal operation";
            break;
        }

        return resp;
    }
    ~NetCal() {}
};